package collage.aminpage;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.DefaultTableModel;

import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class AdminPage_Plus extends JPanel {

	
	
	
	public AdminPage_Plus() {

	setLayout( new BorderLayout(0, 0));	
			
	
	adminTop();
	adminTable();

	}
	
	
	private void adminTable(){
		
		JScrollPane scroll = new JScrollPane();
		
		
		// 테이블 모델 생성 및 수정 불가능하게 설정
		DefaultTableModel model = new DefaultTableModel(){
			@Override
			public boolean isCellEditable(int row, int column) {
				
				return false;
			}
		};

		
		
		// 테이블 생성 - 테스트
		String title[] = { "이것은", "테스트", "입니다"};
		model.setColumnIdentifiers( title );
		
		for ( int i = 1; i <= 50 ; i++){
			model.addRow( new String[]{ i+"", "체크", "요베이베"});
			
		}
		
		// 테이블 생성 SQL문 연결
		/*		
		String title[] = connectAdminSQL();
		model.setColumnIdentifiers( title );
		
		for ( int  i = 0;  i <= 99; i++ ){
			model.addRow( new String[]{ rowSQL } );
			
		}
		*/
		
		JTable table = new JTable();
		table.setModel(model);
		scroll.setViewportView( table );
		
		table.addMouseListener( new MouseAdapter() {
			
			@Override
			public void mouseClicked(MouseEvent e) {
			if ( e.getClickCount() == 2 ){
				
				JTable table = (JTable) e.getSource();
				int row = table.getSelectedRow();//선택행
				
				int col = table.getSelectedColumn();		// 선택열
				String val = (String) table.getValueAt(row, col);
				String msg = row + "/" + col + "/" + val + "\n" + "더브루 클릭크";
				JOptionPane.showMessageDialog(null, msg);
				
				
			}
				super.mouseClicked(e);
			
			
			
			}
						
		});
		
		
		// table
		
		
		
		add( scroll, BorderLayout.CENTER );
		
		
		
		
	}  // adminTable
	
	private void adminTop(){
		
		JPanel top = new JPanel();
		
		JTextField serch = new JTextField();
		serch.setColumns( 30 );
		top.add( serch );	
		
		JButton create = new JButton();
		create.setText( "추 가 등 록" );
		
		
				
		top.add( create );
		add(  top, BorderLayout.NORTH );
		
		
	} // adminTop
	
	
	
	
	
} // class
